/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2019
 */

package net.dreamlu.db.po;


import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.format.annotation.DateTimeFormat;


import lombok.Data;
import lombok.extern.slf4j.Slf4j;
/**
 *
 * @author lambert.wang email:lambert.wang(a)crediteyes.com
 * @version 1.0
 * @since 1.0
 */
@Data
@Slf4j
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "persistent_logins")
public class PersistentLogins implements Serializable {
	private static final long	serialVersionUID	= 5454155825314635342L;
	//alias
	public static final String TABLE_ALIAS = "PersistentLogins";
	public static final String ALIAS_USERNAME = "username";
	public static final String ALIAS_SERIES = "series";
	public static final String ALIAS_TOKEN = "token";
	public static final String ALIAS_LAST_USED = "lastUsed";
	
	public static final String PROP_USERNAME = "username";
	public static final String PROP_SERIES = "series";
	public static final String PROP_TOKEN = "token";
	public static final String PROP_LAST_USED = "lastUsed";
	//columns START
    /**
     * username       db_column: username 
     */ 	
	@Column(name = "username", unique = false, nullable = false, insertable = true, updatable = true, length = 64)
	private java.lang.String username;
    /**
     * series       db_column: series 
     */ 	
	@Id 
	@GeneratedValue(generator="idGenerator")
	@GenericGenerator(name="idGenerator", strategy ="uuid")
	@Column(name = "series", unique = true, nullable = false, insertable = true, updatable = true, length = 64)
	private java.lang.String series;
    /**
     * token       db_column: token 
     */ 	
	@Column(name = "token", unique = false, nullable = false, insertable = true, updatable = true, length = 64)
	private java.lang.String token;
    /**
     * lastUsed       db_column: last_used 
     */ 	
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") 
	@Column(name = "last_used", unique = false, nullable = false, insertable = true, updatable = true, length = 19)
	private java.time.LocalDateTime lastUsed;
	//columns END
	@Override
	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.JSON_STYLE)
			.append(PROP_USERNAME,getUsername())
			.append(PROP_SERIES,getSeries())
			.append(PROP_TOKEN,getToken())
			.append(PROP_LAST_USED,getLastUsed())
			.toString();
	}
	@Override
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getSeries())
			.toHashCode();
	}
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof PersistentLogins == false) return false;
		if(this == obj) return true;
		PersistentLogins other = (PersistentLogins)obj;
		return new EqualsBuilder()
			.append(getSeries(),other.getSeries())
			.isEquals();
	}
	
}
